#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm> 

int main() {
    std::vector<std::string> a = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::vector<int> lst;
    std::string b;
    getline(std::cin, b);
    std::vector<std::string> b_split;
    std::string temp;
    for (char c : b) {
        if (c == ' ') {
            b_split.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    if (!temp.empty()) {
        b_split.push_back(temp);
    }
    
    std::string s;
    int q1 = 0;
    int k = 0;
    int q2 = 0;
    for (int p = 2; p < 1500; ++p) {
        bool pr = true;
        for (int i = 2; i <= static_cast<int>(std::sqrt(p)) + 1; ++i) {
            if (p % i == 0) {
                pr = false;
                break;
            }
        }
        if (pr) {
            lst.push_back(p);
        }
    }
    for (const auto& i : b_split) {
        auto it = std::find(a.begin(), a.end(), i);
        if (it != a.end() && b_split.size() == 3) {
            s += std::to_string(std::distance(a.begin(), it));
            k = 1;
        } else {
            std::cout << "Wrong input\n";
            return 0;
        }
    }
    
    auto it = std::find(lst.begin(), lst.end(), std::stoi(s));
    if (it != lst.end()) {
        std::cout << s << '\n';
    } else if (k == 1) {
        for (int i = 0; i <= 10; ++i) {
            it = std::find(lst.begin(), lst.end(), std::stoi(s) + i);
            if (it != lst.end()) {
                q1 = std::stoi(s) + i;
                break;
            }
        }
        for (int i = -1; i >= -10; --i) {
            it = std::find(lst.begin(), lst.end(), std::stoi(s) + i);
            if (it != lst.end()) {
                q2 = std::stoi(s) + i;
                break;
            }
        }
        if (std::abs(q1 - std::stoi(s)) < std::abs(q2 - std::stoi(s))) {
            std::cout << q1 << '\n';
        } else {
            std::cout << q2 << '\n';
        }
    }
    
    return 0;
}